home *** CD-ROM | disk | FTP | other *** search
/ Scene 96 / Scene 96 International Edition (Zyklop Software) (Disc 2) (1997).iso / graphics / artpacks / acid0896 / bin2xbin.pas < prev    next >
Pascal/Delphi Source File  |  1996-05-18  |  22KB  |  547 lines

  1. {$A+,B-,D+,E+,F-,G-,I+,L+,N-,O-,P-,Q+,R+,S+,T-,V-,X+,Y+}
  2. {$M 4096,0,655360}
  3. PROGRAM BIN_TO_XBIN_Converter;
  4. (*****************************************************************************
  5.  
  6.  BIN to XBIN conversion program.
  7.  
  8.  BIN2XBIN will take a set of BIN files, load them as one big BIN, and then
  9.  write an XBIN file.  When the conditional compilation directive XBIN_RAW
  10.  is {$DEFINE}-ed the XBIN is written as an uncompressed file, when XBIN_RAW
  11.  has not been defined, compression is used.
  12.  
  13.  Most of the code is pretty obvious, the names of the functions/variables and
  14.  the comments should pretty much give you a clue on how things work.
  15.  
  16.  The actual compression routine is what's most important here.  It stands out
  17.  pretty clear using a thick line to indicate it's start and end.
  18.  
  19.  The only other part here worth noting is the way the memory is managed...
  20.  some more about that now.
  21.  
  22.  With Turbo Pascal in real-mode (DOS), you are limited to having datastructures
  23.  (arrays) of maximum 64Kb in size.  Since BIN2XBIN was intended to handle
  24.  pretty big XBIN's (500Kb or so unpacked size) it's obvious some workaround
  25.  was needed...
  26.  
  27.  The BIN is stored as follows
  28.  
  29.      ┌─ BIN, an Array of pointers to BIN-Lines
  30.      
  31.    ┌─────────┐   ┌──────────┬──────────┬──────────┬    ┬──────────┐
  32.    │ Line  1 │-> │ Column 1 │ Column 2 │ Column 3 │ ...│ Column X │
  33.    ├─────────┤   └──────────┴──────────┴──────────┴    ┴──────────┘
  34.    │ Line  2 │->
  35.    ├─────────┤
  36.    │ Line  3 │->
  37.    ├─────────┤
  38.    │ Line  4 │->
  39.    ├─────────┤
  40.    ...
  41.    ├─────────┤
  42.    │ Line  Y │->
  43.    └─────────┘
  44.  
  45.  Since we only allocate as much memory as is needed for the entire BIN, there
  46.  is very little overhead, and we are thus able to load quite big BINs.
  47.  
  48.  Some facts...
  49.    In a pretty normal setup, with say.. 580Mb free, there is about 550Kb free
  50.    for loading the BIN.
  51.    A Normal 80*25 screen takes 4000 Bytes, thus, BIN2XBIN is perfectly capable
  52.    of handling BINs consisting out of 125 80*25 screens.
  53.  
  54.  I don't think the 10*10 screens limit (effectively a bin of 800*250) is really
  55.    a 'limit'. I've not yet seen any ANSi come even close to that.
  56.  
  57. *****************************************************************************)
  58.  
  59. USES  CRT,
  60.       DOS,
  61.       STM;
  62.  
  63. { $DEFINE XBIN_RAW}  { Enable compression or not ? }
  64.  
  65. TYPE  Char4     = ARRAY [0..3] OF Char;
  66.  
  67. Const XB_ID     : Char4 = 'XBIN';
  68. Const MaxBINLine= 2048;                { Max number of lines in the combined BIN }
  69.  
  70. TYPE  XB_Header = RECORD
  71.                     ID      : Char4;
  72.                     EofChar : Byte;
  73.                     Width   : Word;
  74.                     Height  : Word;
  75.                     FontSize: Byte;
  76.                     Flags   : Byte;
  77.                   END;
  78.       BINChr    = RECORD               { BIN Character/Attribute pair. }
  79.                     CASE Boolean OF
  80.                     TRUE  : (
  81.                              CharAttr : Word;
  82.                             );
  83.                     FALSE : (
  84.                              Character : Byte;
  85.                              Attribute : Byte;
  86.                             );
  87.                   END;
  88.  
  89.       BINChrAry = ARRAY[0..32000] OF BINChr;
  90.       BINChrPtr = ^BINChrAry;
  91.  
  92. VAR   XBHdr     : XB_Header;
  93.       BIN       : ARRAY[1..MaxBINLine] OF BINChrPtr;
  94.       BINWidth  : Word;
  95.       BINHeight : Word;
  96.       ErrCode   : Integer;
  97.       XB        : STREAM;              { File stream, see STM unit }
  98.       Lines     : Word;
  99.  
  100.  
  101. { ABORT Execution and display error message }
  102. PROCEDURE Abort (Str: String);
  103. BEGIN
  104.    WriteLn;
  105.    WriteLn('BIN2XBIN V1.00.  Execution aborted.');
  106.    WriteLn;
  107.    WriteLn(Str);
  108.    WriteLn;
  109.    Halt(2);
  110. END;
  111.  
  112.  
  113. { Display command syntax and abort }
  114. PROCEDURE HelpText;
  115. BEGIN
  116.    WriteLn('BIN2XBIN will combine a set of BIN files and will create a compressed XBIN.');
  117.    WriteLn('BIN2XBIN 1.00 does not have support for alternative palettes or fonts.');
  118.    WriteLn;
  119.    WriteLn('Correct Syntax:  BIN2XBIN <BaseName> [Width (defaults to 80)]');
  120.    WriteLn;
  121.    WriteLn('BIN2XBIN expects to find a set of files called BBBBBBxy.BIN');
  122.    WriteLn('  BBBBBB  names the set.');
  123.    WriteLn('  x  is the X-coordinate of the position of the BIN in the total picture');
  124.    WriteLn('  y  is the Y-coordinate of the position of the BIN in the total picture');
  125.    WriteLn;
  126.    WriteLn('Example.  If you wanted to create an XBIN of 160*50 out of 4 80*25 BINs, then');
  127.    WriteLn('they would be named in following way.');
  128.    WriteLn('                  ┌────────────┬────────────┐');
  129.    WriteLn('                  │ NNNN00.BIN │ NNNN10.BIN │');
  130.    WriteLn('                  ├────────────┼────────────┤');
  131.    WriteLn('                  │ NNNN01.BIN │ NNNN11.BIN │');
  132.    WriteLn('                  └────────────┴────────────┘');
  133.    WriteLn('All BINs must be of identical size and must not contain SAUCE information');
  134.    WriteLn;
  135.    WriteLn('Unless an error occurs, BIN2XBIN will have created a file named BBBBBB.XB');
  136.    Writeln;
  137.    Halt(1);
  138. END;
  139.  
  140.  
  141. { Return size of File in Bytes or -1 if it does not exist or can't determine }
  142. { size                                                                       }
  143. FUNCTION FileExist (FName:String) : LongInt;
  144. VAR F      : FILE;
  145. BEGIN
  146.   {$i-}
  147.   ASSIGN(F,FName);
  148.   RESET(F,1);
  149.   IF (IOResult=0) THEN BEGIN
  150.      FileExist := FileSize(F);          { Return Size of file        }
  151.      IF (IOResult<>0) THEN
  152.         FileExist:=-1;                  { Return -1 : File not Found }
  153.      Close(F);
  154.   END
  155.   ELSE
  156.      FileExist:=-1;                     { Return -1 : File not Found }
  157.   {$i+}
  158. END;
  159.  
  160.  
  161. { Load multiple BIN files as one BIG BIN }
  162. PROCEDURE LoadBIN (BaseName : String);
  163. VAR B         : FILE;
  164.     X, XMax   : Char;
  165.     Y, YMax   : Char;
  166.     FSize     : LongInt;
  167.     Tel       : Word;
  168.     BytesRead : Word;
  169.     XPos      : Word;
  170.     YPos      : Word;
  171. BEGIN
  172.   XMax:='0';
  173.   YMax:='0';
  174.   FSize:=FileExist(BaseName+'00.BIN');
  175.   IF (FSize<=0) THEN
  176.      Abort('Filename '+BaseName+'00.BIN not found or 0 size.');
  177.  
  178.   { Determine maximum valid value for 'X' parameter in BIN name }
  179.   WHILE (FileExist(BaseName+XMax+'0.BIN')>=0) AND (XMax<='9') DO Inc(XMax);
  180.   Dec(XMax);              { Last value we tried was NOT valid, so backup one }
  181.  
  182.   { Determine maximum valid value for 'Y' parameter in BIN name }
  183.   WHILE (FileExist(BaseName+'0'+YMax+'.BIN')>=0) AND (YMax<='9') DO Inc(YMax);
  184.   Dec(YMax);              { Last value we tried was NOT valid, so backup one }
  185.  
  186.   { --- Calculate number of lines in a single BIN --- }
  187.   BINHeight := FSize DIV (BINWidth*2);
  188.   { --- Calculate width of combined BINs --- }
  189.   XBHdr.Width:=(Ord(XMax)-Ord('0')+1)*BINWidth;
  190.   { --- Calculate height of combined BINs --- }
  191.   XBHdr.Height:=(Ord(YMax)-Ord('0')+1)*BINHeight;
  192.  
  193.   { --- NOW We want to allocate XBHdr.Height lines of XBHdr.Width character/ }
  194.   {     attribute pairs of memory for loading the entire combined BIN        }
  195.   IF (XBHdr.Height>MaxBINLine) THEN
  196.      Abort('Combined BINS contain more lines than currently possible.'+#10#13+
  197.            'Raise the value of <MaxBINLine> in the source and recompile.');
  198.  
  199.   FOR Tel:=1 to XBHdr.Height DO BEGIN
  200.      IF (MaxAvail<XBHdr.Height*XBHdr.Width*2) THEN
  201.         Abort('Not enough memory to load all BINs of the set.');
  202.      getmem(BIN[Tel],XBHdr.Width*2);
  203.   END;
  204.  
  205.   { --- Load all BINs --- }
  206.   WriteLn ('Loading ',XMax,' by ',YMax,' BINs of ',BINWidth,' by ',BINHeight,' Characters');
  207.  
  208.   FOR Y:='0' to YMax DO BEGIN            { Get all BINs on Y axis }
  209.      FOR X:='0' to XMax DO BEGIN         { Get all BINs on X axis }
  210.         Write(BaseName,X,Y,'.BIN',#13);
  211.         {$i-}
  212.         ASSIGN(B,BaseName+X+Y+'.BIN');
  213.         RESET(B,1);
  214.         IF (IOResult=0) THEN BEGIN
  215.            FOR Tel:=1 TO XBHdr.Height DO BEGIN { Read All lines }
  216.               Write(BaseName,X,Y,'.BIN Line:',Tel,'/',XBHdr.Height,#13);
  217.               YPos:=(Ord(Y)-Ord('0'))*BINHeight+Tel;
  218.               XPos:=(Ord(X)-Ord('0'))*BINWidth*2;
  219.               BlockRead(B,BIN[YPos]^[XPos],BINWidth*2,BytesRead);
  220.               IF (BytesRead<>BINWidth*2) THEN
  221.                  Abort('Error reading file '+BaseName+X+Y+'.BIN');
  222.            END;
  223.            Close(B);
  224.         END
  225.         ELSE
  226.            Abort('Error opening file '+BaseName+X+Y+'.BIN');
  227.         {$i+}
  228.      END;
  229.   END;
  230.   WriteLn('':79,#13,'Loading completed');
  231. END;
  232.  
  233.  
  234. {███ XBIN Compression START █████████████████████████████████████████████████}
  235.  
  236. {
  237.   Introductory note.
  238.  
  239.   The XBIN compression used here is a single step compression algorythm.
  240.   What this means is that we will compress the data one character/attribute
  241.   pair at a time letting that char/attr pass through all the necessary
  242.   conditions until it has been decided what has to be done with it.
  243.   While not being the fastest or most compact algorythm available, it does
  244.   make the algorythm a lot easier to understand.
  245.  
  246.   This XBIN compression routine uses a temporary buffer (an array) to hold
  247.   the current run-count and compressed data.  Since the maximum run-count is
  248.   64, this buffer only needs to be 129 bytes in size (1 byte for the
  249.   run-count, and 64 times a char/attr pair when no compression is taking
  250.   place.
  251.  
  252.   The overall idea behind this routine is pretty simple..  here's the rough
  253.   outline:
  254.  
  255.   WHILE (Still_characters_to_process)
  256.      IF (A_run_is_busy)
  257.         IF (Stop_this_run_for_whatever_reason)
  258.            Write_run_to_disk;
  259.         ENDIF
  260.      ENDIF
  261.      IF (Run_is_still_busy)
  262.         add_current_char/attr_pair_to_run;
  263.      ELSE
  264.         start_a_new_run_with_char/attr_pair;
  265.      ENDIF
  266.   ENDWHILE
  267.   IF (A_run_is_busy)
  268.      Write_run_to_disk;
  269.   ENDIF
  270.  
  271.   It looks simple, but implementing it effectively is tricky.  The most
  272.   involving part will be the "Stop_this_run_for_whatever_reason" routine.
  273.   There are several reasons for wishing to stop the run.
  274.     1) The current run is 64 characters wide, thus, another char/attr pair
  275.        can't be added.
  276.     2) The current compression can no longer be maintained as the new
  277.        char/attr pair does not match.
  278.     3) Aborting the run prematurely offers a possibility to restart using a
  279.        better compression method.
  280.   Reasons 1 and 2, are easy enough to deal with, the third provides the path
  281.   to optimal compression.  The better the conditions are made for aborting in
  282.   favour of a better compression method, the better compression will be.
  283.  
  284.   Enough about theory, on to the actual code.
  285. }
  286.  
  287. PROCEDURE XBIN_Compress (VAR BIN:BINChrAry; BIN_Width : WORD);
  288.  
  289. CONST NO_COMP       = $00;
  290.       CHAR_COMP     = $40;
  291.       ATTR_COMP     = $80;
  292.       CHARATTR_COMP = $C0;
  293.  
  294. VAR   CompressBuf   : Array[0..2*64] of Byte;
  295.       RunCount      : Word;
  296.       RunMode       : Byte;
  297.       RunChar       : BINChr;
  298.       CB_Index      : Word;            { Index into CompressBuf               }
  299.       BIN_Index     : Word;            { Index into BIN_Line                  }
  300.       EndRun        : Boolean;
  301.  
  302. BEGIN
  303.   RunCount := 0;                       { There's no run busy                  }
  304.   BIN_Index:= 0;
  305.  
  306.   WHILE (BIN_Index<BIN_Width) DO BEGIN { Still characters to process ?        }
  307.      IF (RunCount>0) THEN BEGIN        { A run is busy                        }
  308.         EndRun := FALSE;               { Assume we won't need to end the run  }
  309.  
  310.         IF (RunCount=64) THEN BEGIN    { We reached the longest possible run? }
  311.            EndRun:=TRUE;               { Yes, end the current run             }
  312.         END
  313.         ELSE BEGIN
  314.            { A run is currently busy.  Check to see if we can/will continue...}
  315.            CASE RunMode OF
  316.               NO_COMP       : BEGIN
  317.                 { No compression can always continue, since it does not       }
  318.                 { require on the character and/or attribute to match its      }
  319.                 { predecessor                                                 }
  320.  
  321.                 { === No compression run.  Aborting this will only have       }
  322.                 {     benefit if we can start a run of at least 3 character   }
  323.                 {     or attribute compression. OR a run of at least 2        }
  324.                 {     char/attr compression                                   }
  325.                 {     The required run of 3 (2) takes into account the fact   }
  326.                 {     that a run must be re-issued if no more than 3 (2)      }
  327.                 {     BIN pairs can be compressed                             }
  328.                 IF (BIN_Width-BIN_Index>=2) AND
  329.                    (BIN[BIN_Index].CharAttr=BIN[BIN_Index+1].CharAttr) THEN BEGIN
  330.                    EndRun:=TRUE;
  331.                 END
  332.                 ELSE IF (BIN_Width-BIN_Index>=3) AND
  333.                         (BIN[BIN_Index].Character=BIN[BIN_Index+1].Character) AND
  334.                         (BIN[BIN_Index].Character=BIN[BIN_Index+2].Character) THEN BEGIN
  335.                    EndRun:=TRUE;
  336.                 END
  337.                 ELSE IF (BIN_Width-BIN_Index>=3) AND
  338.                         (BIN[BIN_Index].Attribute=BIN[BIN_Index+1].Attribute) AND
  339.                         (BIN[BIN_Index].Attribute=BIN[BIN_Index+2].Attribute) THEN BEGIN
  340.                    EndRun:=TRUE;
  341.                 END
  342.               END;
  343.  
  344.               CHAR_COMP     : BEGIN
  345.                 { Character compression needs to be ended when the new        }
  346.                 { character no longer matches the run-character               }
  347.                 IF (BIN[BIN_Index].Character<>RunChar.Character) THEN BEGIN
  348.                    EndRun:=TRUE;
  349.                 END
  350.                 { === Aborting an character compression run will only have    }
  351.                 {     benefit if we can start a run of at least 3 char/attr   }
  352.                 {     pairs.                                                  }
  353.                 ELSE IF (BIN_Width-BIN_Index>=3) AND
  354.                         (BIN[BIN_Index].CharAttr=BIN[BIN_Index+1].CharAttr) AND
  355.                         (BIN[BIN_Index].CharAttr=BIN[BIN_Index+2].CharAttr) THEN BEGIN
  356.                    EndRun:=TRUE;
  357.                 END
  358.               END;
  359.  
  360.               ATTR_COMP     : BEGIN
  361.                 { Attribute compression needs to be ended when the new        }
  362.                 { attribute no longer matches the run-attribute               }
  363.                 IF (BIN[BIN_Index].Attribute<>RunChar.Attribute) THEN BEGIN
  364.                    EndRun:=TRUE;
  365.                 END
  366.                 { === Aborting an attribute compression run will only have    }
  367.                 {     benefit if we can start a run of at least 3 char/attr   }
  368.                 {     pairs.                                                  }
  369.                 ELSE IF (BIN_Width-BIN_Index>=3) AND
  370.                         (BIN[BIN_Index].CharAttr=BIN[BIN_Index+1].CharAttr) AND
  371.                         (BIN[BIN_Index].CharAttr=BIN[BIN_Index+2].CharAttr) THEN BEGIN
  372.                    EndRun:=TRUE;
  373.                 END
  374.               END;
  375.  
  376.               CHARATTR_COMP : BEGIN
  377.                 { Character/Attribute compression needs to be ended when the  }
  378.                 { new char/attr no longer matches the run-char/attr           }
  379.                 IF (BIN[BIN_Index].CharAttr<>RunChar.CharAttr) THEN BEGIN
  380.                    EndRun:=TRUE;
  381.                 END
  382.                 { === Aborting a char/attr compression will never yield any   }
  383.                 {     benefit                                                 }
  384.               END;
  385.            END; { CASE }
  386.         END; { IF }
  387.  
  388.         IF EndRun THEN BEGIN
  389.            CompressBuf[0] := RunMode + (RunCount-1);
  390.            STM_Write(XB,CompressBuf,CB_Index);
  391.            IF (XB.LastErr<>STM_OK) THEN Abort('Error Writing File');
  392.  
  393.            RunCount:=0;                { Run no longer busy                   }
  394.         END; { IF }
  395.      END; { IF }
  396.  
  397.      IF (RunCount>0) THEN BEGIN        { Run is still busy ?                  }
  398.          { === Add new char/attr to current run as appropriate for compression}
  399.          {     method in use                                                  }
  400.          CASE RunMode OF
  401.             NO_COMP       : BEGIN
  402.                { Store Char/Attr pair                                         }
  403.                CompressBuf[CB_Index]:=BIN[BIN_Index].Character;
  404.                CompressBuf[CB_Index+1]:=BIN[BIN_Index].Attribute;
  405.                Inc(CB_Index,2);
  406.             END;
  407.  
  408.             CHAR_COMP     : BEGIN
  409.                { Store Attribute                                              }
  410.                CompressBuf[CB_Index]:=BIN[BIN_Index].Attribute;
  411.                Inc(CB_Index);
  412.             END;
  413.  
  414.             ATTR_COMP     : BEGIN
  415.                { Store character                                              }
  416.                CompressBuf[CB_Index]:=BIN[BIN_Index].Character;
  417.                Inc(CB_Index);
  418.             END;
  419.  
  420.             CHARATTR_COMP : BEGIN
  421.                { Nothing to change, only RunCount ever changes                }
  422.             END;
  423.          END;
  424.      END
  425.      ELSE BEGIN                        { Run not busy, Start a new one        }
  426.          CB_Index := 1;                { Skip index 0 (for run-count byte)    }
  427.  
  428.          IF (BIN_Width-BIN_Index>=2) THEN BEGIN { At least 2 more to do       }
  429.             IF (BIN[BIN_Index].CharAttr=BIN[BIN_Index+1].CharAttr) THEN
  430.                { === We can use char/attr compression                         }
  431.                RunMode:=CHARATTR_COMP
  432.             ELSE IF (BIN[BIN_Index].Character=BIN[BIN_Index+1].Character) THEN
  433.                { === We can use character compression                         }
  434.                RunMode:=CHAR_COMP
  435.             ELSE IF (BIN[BIN_Index].Attribute=BIN[BIN_Index+1].Attribute) THEN
  436.                { === We can use attribute compression                         }
  437.                RunMode:=ATTR_COMP
  438.             ELSE
  439.                { === We can't use any compression                             }
  440.                RunMode:=NO_COMP;
  441.          END
  442.          ELSE                          { Last character, use no-compression   }
  443.             RunMode:=NO_COMP;
  444.  
  445.          IF (RunMode=ATTR_COMP) THEN BEGIN
  446.                                        { Attr compression has Attr first !!   }
  447.             CompressBuf[CB_Index]:=BIN[BIN_Index].Attribute;
  448.             CompressBuf[CB_Index+1]:=BIN[BIN_Index].Character;
  449.          END
  450.          ELSE BEGIN
  451.             CompressBuf[CB_Index]:=BIN[BIN_Index].Character;
  452.             CompressBuf[CB_Index+1]:=BIN[BIN_Index].Attribute;
  453.          END;
  454.  
  455.          Inc(CB_Index,2);
  456.          RunChar.CharAttr:=BIN[BIN_Index].CharAttr;
  457.      END; { IF }
  458.  
  459.      Inc(RunCount);                    { RunCount is now one more             }
  460.      Inc(BIN_Index);                   { One char/attr pair processed         }
  461.   END;
  462.  
  463.   IF (RunCount>0) THEN BEGIN
  464.      CompressBuf[0] := RunMode + (RunCount-1);
  465.      STM_Write(XB,CompressBuf,CB_Index);
  466.      IF (XB.LastErr<>STM_OK) THEN Abort('Error Writing File');
  467.   END;
  468. END;
  469.  
  470. {███ XBIN Compression END ███████████████████████████████████████████████████}
  471.  
  472.  
  473. BEGIN { *** MAIN *** }
  474.   WriteLn ('BIN TO XBIN Converter V1.00.');
  475.   WriteLn ('Coded by Tasmaniac / ACiD.');
  476.   WriteLn ('Sourcecode placed into the public domain, use and modify freely');
  477.   WriteLn;
  478.  
  479.   { --- Check passed parameter ------------------------------------------- }
  480.   IF (ParamCount<>1) AND (ParamCount<>2) THEN HelpText;
  481.  
  482.   { --- Complete XBIN Header --------------------------------------------- }
  483.   IF (ParamCount=2) THEN BEGIN
  484.      Val(ParamStr(2),BINWidth,ErrCode);
  485.      IF ErrCode<>0 THEN Abort('Invalid width specified');
  486.   END
  487.   ELSE
  488.      BINWidth:=80;
  489.  
  490.   { --- Load BIN's ------------------------------------------------------- }
  491.   LoadBIN(ParamStr(1));
  492.  
  493.   { ===========================  CREATE XBIN  ============================ }
  494.   STM_Create(XB,Paramstr(1)+'.XB');
  495.   IF (XB.LastErr<>STM_OK) THEN Abort('Error creating XBIN file '+ParamStr(1)+'.XB');
  496.  
  497.   XBHdr.ID      := XB_ID; { 'XBIN' ID                       }
  498.   XBHdr.EofChar := 26;    { Mark EOF when TYPEing XBIN      }
  499. { XBHDr.Width   :=          Already filled in by LoadBIN()  }
  500. { XBHdr.Height  :=          Already filled in by LoadBIN()  }
  501.   XBHdr.FontSize:= 16;    { Default font is 16 pixels high  }
  502.   {$IFDEF XBIN_RAW}
  503.      XBHdr.Flags   := $00;{ Compression disabled. no special features are enabled }
  504.  
  505.      { --- Write Header ----------------------------------------------------- }
  506.      WriteLn('Writing XBIN Header');
  507.      STM_Write(XB,XBHdr,Sizeof(XBHdr));
  508.      IF (XB.LastErr<>STM_OK) THEN Abort('Error Writing XBIN File');
  509.  
  510.      { --- Write image data ------------------------------------------------- }
  511.      WriteLn('Writing uncompressed image data');
  512.      FOR Lines:=1 to XBHdr.Height DO BEGIN
  513.         Write(Lines,'/',XBHdr.Height,#13);
  514.         STM_Write(XB,BIN[Lines]^,XBHdr.Width*2);
  515.         IF (XB.LastErr<>STM_OK) THEN Abort('Error Writing File');
  516.      END;
  517.      Write('':79,#13);
  518.  
  519.   {$ELSE}
  520.      XBHdr.Flags   := $04;{ Compression enabled. no special features are enabled }
  521.  
  522.      { --- Write Header ----------------------------------------------------- }
  523.      WriteLn('Writing XBIN Header');
  524.      STM_Write(XB,XBHdr,Sizeof(XBHdr));
  525.      IF (XB.LastErr<>STM_OK) THEN Abort('Error Writing XBIN File');
  526.  
  527.      { --- Write image data ------------------------------------------------- }
  528.      WriteLn('Writing compressed image data');
  529.      FOR Lines:=1 to XBHdr.Height DO BEGIN
  530.         Write(Lines,'/',XBHdr.Height,#13);
  531.         XBIN_Compress(BIN[Lines]^,XBHdr.Width);
  532.      END;
  533.      Write('':79,#13);
  534.  
  535.   {$ENDIF}
  536.  
  537.   STM_Close(XB);
  538.  
  539.   WriteLn ('Conversion complete.');
  540. END.
  541.  
  542.  
  543.  
  544.  
  545.  
  546.  
  547.